/*
 * @Author: 杨三炮
 * @Date: 2021-11-20 13:32:34
 * @LastEditors: 杨三炮
 * @LastEditTime: 2021-11-23 18:44:00
 * @FilePath: \node\node\model\student_mod.js
 */
module.exports = class student_mod extends require('./model') {

    /**
     * @description: 我的通知分页获取数据
     * @param {*} u_classes 班级
     * @param {*} pageNum   每页多少个
     * @param {*} currPage  第几页
     * @return {*}
     */
    static getNoticeMod (class_id) {
        return new Promise((resolve, reject) => {
            let sql = `SELECT *FROM class AS c
            INNER JOIN noticeclass AS nc
            ON c.c_id=nc.class_id
            INNER JOIN notice as n
            ON nc.n_id=n.n_id
            WHERE c.c_id=?; `
            this.query(sql, this.formatParams(class_id)).then(result => {
                resolve(result)
            }).catch(err => {
                reject(err)
            })
        })
    }
    /**
     * @description: 我的通知数量
     * @param {*} u_classes 班级
     * @return {*}
     */
    static getNoticeTotalMod (u_classes) {
        return new Promise((resolve, reject) => {
            let sql = `SELECT COUNT(1) as count FROM class AS c
            INNER JOIN noticeclass AS nc
            ON c.c_id=nc.class_id
            INNER JOIN notice as n
            ON nc.n_id=n.n_id
            WHERE c.c_id=${u_classes}; `
            this.query(sql).then(result => {
                resolve(result[0].count)
            }).catch(err => {
                reject(err)
            })
        })
    }

    /**
     * @description: 获取的我通知已读列表(供已读未读状态渲染)
     * @param {*} u_id
     * @return {*}
     */
    static getNoticeReadMod (u_id) {
        return new Promise((resolve, reject) => {
            let sql = "SELECT * FROM `read` WHERE u_id=? ;"
            this.query(sql, this.formatParams(u_id)).then(result => {
                resolve(result)
            }).catch(err => {
                reject(err)
            })
        })
    }
    /**
     * @description: 已读转未读
     * @param {*} u_id
     * @param {*} n_id
     * @return {*}
     */
    static goweiduMod (u_id, n_id) {
        return new Promise((resolve, reject) => {
            let sql = "DELETE FROM `read` WHERE u_id=? AND n_id=?"
            this.query(sql, this.formatParams(u_id, n_id)).then(result => {
                resolve(1)
            }).catch(err => {
                reject(0)
            })
        })
    }
    /**
     * @description: 未读转已读
     * @param {*} u_id
     * @return {*}
     */
    static goyiduMod (u_id, n_id) {
        return new Promise((resolve, reject) => {
            let sql = "INSERT INTO `read` (u_id,n_id,readtime) VALUES (?,?,NOW());"
            this.query(sql, this.formatParams(u_id, n_id)).then(result => {
                resolve(1)
            }).catch(err => {
                reject(0)
            })
        })
    }

    /**
     * @description: 健康填报表提交操作
     * @param {*} info
     * @return {*}
     */
    static sethealthMod (healthInfo) {
        return new Promise((resolve, reject) => {
            let sql = `INSERT INTO health (u_id,temperature,hot,gohubei,hubeiren,fever,leaveout,hesuan,mask,masknum,kills,createtime)VALUES
            (?,?,?,?,?,?,?,?,?,?,?,NOW());`
            let params = [healthInfo.u_id,
            healthInfo.temperature,
            healthInfo.hot,
            healthInfo.gohubei,
            healthInfo.hubeiren,
            healthInfo.fever,
            healthInfo.leaveout,
            healthInfo.hesuan,
            healthInfo.mask,
            healthInfo.masknum,
            healthInfo.kills,
            ]
            this.query(sql, params).then(result => {
                resolve(result)
            }).catch(err => {
                reject(err)
            })
        })
    }

    /**
     * @description: 获取当天所有报表
     * @param {*} newDate
     * @param {*} lastDate
     * @param {*} pageNum
     * @param {*} currPage
     * @return {*}
     */
    static gethealthNowDayPageMod (newDate, lastDate, pageNum, currPage) {
        pageNum = Number(pageNum)
        currPage = currPage * pageNum
        return new Promise((resolve, reject) => {
            let sql = `SELECT *FROM health WHERE createtime BETWEEN ? AND ? LIMIT ?,?;`
            this.query(sql, this.formatParams(newDate, lastDate, currPage, pageNum))
                .then(result => {
                    resolve(result)
                }).catch(err => {
                    reject(err)
                })
        })
    }
    /**
     * @description: 获取当天所有报表的数量
     * @param {*} newDate
     * @param {*} lastDate
     * @return {*}
     */
    static gethealthNowDayPageToalMod (newDate, lastDate) {
        return new Promise((resolve, reject) => {
            let sql = `SELECT count(1) as count FROM health WHERE createtime BETWEEN ? AND ?;`
            this.query(sql, this.formatParams(newDate, lastDate))
                .then(result => {
                    resolve(result[0].count)
                }).catch(err => {
                    reject(err)
                })
        })
    }

    /**
     * @description: 获取当天某用户的报表
     * @param {*} req
     * @param {*} res
     * @return {*}
     */
    static getHealthNowDayByidMod (u_id, newDate, lastDate) {
        return new Promise((resolve, reject) => {
            let sql = `SELECT *FROM health WHERE u_id=? AND createtime BETWEEN ? AND ?; `
            this.query(sql, this.formatParams(u_id, newDate, lastDate)).then(result => {
                resolve(result)
            }).catch(err => {
                reject(err)
            })
        })
    }

    static gethealthNowDayMod (newDate, lastDate) {
        return new Promise((resolve, reject) => {
            let sql = `SELECT *FROM health WHERE createtime BETWEEN ? AND ?; `
            this.query(sql, this.formatParams(newDate, lastDate)).then(result => {
                resolve(result)
            }).catch(err => {
                reject(err)
            })
        })
    }
    /**
     * @description: 获取当月所有报表
     * @param {*} firstMonthDay
     * @param {*} lastMonthDay
     * @return {*}
     */
    static gethealthNowMonthMod (firstMonthDay, lastMonthDay) {
        return new Promise((resolve, reject) => {
            let sql = `SELECT *FROM health WHERE  createtime BETWEEN ? AND ?; `
            this.query(sql, this.formatParams(firstMonthDay, lastMonthDay)).then(result => {
                resolve(result)
            }).catch(err => {
                reject(err)
            })
        })
    }
    /**
     * @description: 获取所有报表
     * @param {*}
     * @return {*}
     */
    static getAllHealthMod () {
        return new Promise((resolve, reject) => {
            let sql = `SELECT *FROM health; `
            this.query(sql).then(result => {
                resolve(result)
            }).catch(err => {
                reject(err)
            })
        })
    }


    /**
     * @description: 请假条
     * @param {*} data
     * @return {*}
     */
    static setLeaveMod (data) {
        console.log(data)
        return new Promise((resolve, reject) => {
            let sql = "INSERT INTO `leave` (u_id,reason,leavetype,starttime,endtime,state,createtime) VALUES (?,?,?,?,?,0,NOW()); "
            let params = [data.u_id, data.reason, data.leavetype, data.starttime, data.endtime]
            this.query(sql, params).then(result => {
                resolve(result)
            }).catch(err => {
                reject(err)
            })
        })
    }



}